#include "app_data.h"

// SmartLamp 地址  e0:98:06:f8:5a:58
uint8_t SmartLamp_Address[] = {0xE0, 0x98, 0x06, 0xF8, 0x5A, 0x58};

lamp_state_data SmartLamp_data = {
    .lampdata1 = LAMP_CHANGE_COLORT_MODE,
    .lampdata2 = 127,
    .lampdata3 = 127,
    .lampdata4 = 0,
    .lampdata5 = 0,
};

SmartLamp_data_refresh lampdata_refresh = {
    .lamp_mode = LAMP_CHANGE_COLORT_MODE,
    .brightness = 127,
    .colorT = 127,
    .volume = 80,    // 音量降噪
    .rgb_mode = 1,   // 彩灯模式
    .lamp_hsv = 255, // 彩灯色值
    .delay_time = 0, // 定时时长
    .setting = 0     // 设置
};

void key_board_change_lamp_state(uint8_t lamp_state, uint8_t key_state) // 智能键盘按键按下时改变台灯亮度或色温
{
      if (key_state == key_press)
      {
            SmartLamp_data.lampdata1 = SmartKB32_KEY;
            SmartLamp_data.lampdata2 = lamp_state;
            SmartLamp_data.lampdata3 = key_press;
            SmartLamp_data.lampdata4 = 0;
            SmartLamp_data.lampdata5 = 0;
      }
      else if (key_state == key_square)
      {
            SmartLamp_data.lampdata1 = SmartKB32_KEY;
            SmartLamp_data.lampdata2 = lamp_state;
            SmartLamp_data.lampdata3 = key_square;
            SmartLamp_data.lampdata4 = 0;
            SmartLamp_data.lampdata5 = 0;
      }
      esp_now_send(SmartLamp_Address, (uint8_t *)&SmartLamp_data, sizeof(SmartLamp_data));
      delay(200);
}

void tx_lampdata_to_SmartLamp(const char *leixin)
{
      switch (lampdata_refresh.lamp_mode)
      {
      case LAMP_CHANGE_COLORT_MODE: // 调色温模式
            SmartLamp_data.lampdata1 = lampdata_refresh.lamp_mode;
            SmartLamp_data.lampdata2 = lampdata_refresh.brightness;
            SmartLamp_data.lampdata3 = lampdata_refresh.colorT;
            SmartLamp_data.lampdata4 = lampdata_refresh.delay_time;
            SmartLamp_data.lampdata5 = lampdata_refresh.setting;
            break;
      case LAMP_COMPUTER_MODE: // 电脑模式
            SmartLamp_data.lampdata1 = lampdata_refresh.lamp_mode;
            SmartLamp_data.lampdata2 = lampdata_refresh.brightness;
            SmartLamp_data.lampdata3 = lampdata_refresh.colorT;
            SmartLamp_data.lampdata4 = lampdata_refresh.delay_time;
            SmartLamp_data.lampdata5 = lampdata_refresh.setting;
            break;
      case LAMP_READ_MODE: // 阅读模式
            SmartLamp_data.lampdata1 = lampdata_refresh.lamp_mode;
            SmartLamp_data.lampdata2 = lampdata_refresh.brightness;
            SmartLamp_data.lampdata3 = lampdata_refresh.colorT;
            SmartLamp_data.lampdata4 = lampdata_refresh.delay_time;
            SmartLamp_data.lampdata5 = lampdata_refresh.setting;
            break;
      case LAMP_COZY_HOME_MODE: // 温馨模式
            SmartLamp_data.lampdata1 = lampdata_refresh.lamp_mode;
            SmartLamp_data.lampdata2 = lampdata_refresh.brightness;
            SmartLamp_data.lampdata3 = lampdata_refresh.colorT;
            SmartLamp_data.lampdata4 = lampdata_refresh.delay_time;
            SmartLamp_data.lampdata5 = lampdata_refresh.setting;
            break;
      case LAMP_CINEMA_MODE: // 电影院模式
            SmartLamp_data.lampdata1 = lampdata_refresh.lamp_mode;
            SmartLamp_data.lampdata2 = lampdata_refresh.brightness;
            SmartLamp_data.lampdata3 = lampdata_refresh.colorT;
            SmartLamp_data.lampdata4 = lampdata_refresh.delay_time;
            SmartLamp_data.lampdata5 = lampdata_refresh.setting;
            break;
      case LAMP_MUSIC_MODE: // 音乐模式
            SmartLamp_data.lampdata1 = lampdata_refresh.lamp_mode;
            SmartLamp_data.lampdata2 = lampdata_refresh.brightness;
            SmartLamp_data.lampdata3 = lampdata_refresh.colorT;
            SmartLamp_data.lampdata4 = lampdata_refresh.volume;
            SmartLamp_data.lampdata5 = lampdata_refresh.rgb_mode;
            break;
      case LAMP_RGB_MODE: // 彩灯模式
            SmartLamp_data.lampdata1 = lampdata_refresh.lamp_mode;
            SmartLamp_data.lampdata2 = lampdata_refresh.brightness;
            SmartLamp_data.lampdata3 = lampdata_refresh.colorT;
            SmartLamp_data.lampdata4 = lampdata_refresh.lamp_hsv;
            SmartLamp_data.lampdata5 = lampdata_refresh.rgb_mode;
            break;
      }
      esp_now_send(SmartLamp_Address, (uint8_t *)&SmartLamp_data, sizeof(SmartLamp_data));
      delay(200);
}

